import { defineStore } from 'pinia'
import type { LayoutRoute } from '@/types'

export const useLayoutRouterStore = defineStore(
  'LayoutRouterStore',
  () => {
    const menuContents = ref<LayoutRoute[]>([
      {
        path: '/welcome',
        meta: { title: '欢迎页' },
      },
    ])

    // 删除菜单项
    function removeMenuContent(path: string): LayoutRoute {
      menuContents.value = menuContents.value.filter((item) => {
        return item.path !== path
      })
      //激活最后一个
      const menuContent = menuContents.value[menuContents.value.length - 1]

      return menuContent
    }

    return { menuContents, removeMenuContent }
  },
  {
    persist: {
      key: 'LayoutRouterStore', //存储名称
      storage: sessionStorage, // 存储方式
      pick: ['menuContents'],
    },
  },
)
